<script setup>
import { reactive, inject, ref, onMounted } from 'vue'
import { ElMessage } from 'element-plus'

import http from '../../../api/http.js'
import { useRouter } from 'vue-router'
import RecordIndex from '../../main_frame/components/RecordIndex.vue'
const router = useRouter()
let userLogin = reactive({
    identity: '',
    password: ''
})

const userSubmit = () => {
    http.post({
        url: '/users/login',
        data: userLogin
    })
        .then((res) => {
            console.log('用户登录成功', res)
            localStorage.setItem('token', res.data.data)

            ElMessage({
                dangerouslyUseHTMLString: true,
                showClose: true,
                message: '<div class="tip">登录成功</div>',
                type: 'success'
            })
            router.push({
                path: '/mainFrame/recordIndex',
                component: RecordIndex
            })
        })
        .catch((err) => {
            ElMessage({
                dangerouslyUseHTMLString: true,
                showClose: true,
                message: '<div class="tip">用户名或密码输入错误</div>',
                type: 'error'
            })
            console.log('登录失败', err)
        })
}

onMounted(() => {})
</script>

<template>
    <div class="login">
        <div class="text">
            <div class="big" @click="test">注册登录页面</div>
            <div class="small">
                欢迎使用肺癌诊断系统，请填写以下信息进行注册或登录。
            </div>
        </div>
    </div>
    <div class="input_container">
        <div class="input_text">用户名</div>
        <input
            class="input"
            type="text"
            v-model="userLogin.identity"
            placeholder="请输入用户名"
        />
        <div class="input_text">密码</div>
        <input
            class="input"
            type="password"
            v-model="userLogin.password"
            placeholder="请输入密码"
        />
    </div>
    <div class="btn">
        <el-button class="submit" @click="userSubmit">提交</el-button>
    </div>
    <div class="color"></div>
</template>

<style scoped>
.text {
    text-align: center;
}
.big {
    margin: 50px 0 20px 0;
    font-size: 48px;
    font-weight: 700;
    line-height: 56px;
    color: rgba(29, 33, 41, 1);
    vertical-align: top;
}

.small {
    /* margin: 0 auto; */

    font-size: 18px;
    font-weight: 400;
    line-height: 28px;
    color: rgba(29, 33, 41, 1);
    vertical-align: top;
}

.input_container {
    margin-top: 100px;
    margin-left: 33%;
}
.input_text:nth-child(n) {
    margin: 25px 0 25px 0;
}
.input_text {
    /** 文本1 */
    font-size: 25px;
    font-weight: 400;
    line-height: 24px;
    color: rgba(29, 33, 41, 1);
    text-align: left;
    vertical-align: top;
}
.input {
    position: relative; /* 确保 .btn 是定位上下文 */
    z-index: 1; /* 提升 .btn 的 z-index */
    font-size: 16px;
    outline: none;
    padding-left: 15px;
    width: 336px;
    height: 52px;
    opacity: 1;
    border-radius: 40px;
    background: rgba(255, 255, 255, 1);
    border: 1px solid rgba(0, 0, 0, 0.1);
}

.input:focus {
    border: 1px solid rgba(0, 0, 0, 0.6);
}
.btn {
    text-align: center;
    margin-top: 10%;
}
.submit {
    color: aliceblue;
    width: 720px;
    height: 52px;
    border-radius: 175px;
    background: rgba(0, 0, 255, 1);
}

.color {
    float: left;
    position: absolute;
    top: 500px;
    left: 800px;
    width: 509.06px;
    height: 156.52px;
    opacity: 1;
    transform: rotate(31.71deg);
    background: linear-gradient(
        90deg,
        rgba(240, 0, 240, 0.15) 0%,
        rgba(0, 128, 255, 0.15) 45.84%,
        rgba(21, 0, 255, 0.15) 100%
    );
    filter: blur(100px);
}
</style>
